package com.meida.module.bus.provider.service.impl;

import com.meida.module.bus.client.entity.BusOrderQuestion;
import com.meida.module.bus.provider.mapper.BusOrderQuestionMapper;
import com.meida.module.bus.provider.service.BusOrderQuestionService;
import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;
import com.meida.common.base.entity.EntityMap;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.mybatis.query.CriteriaSave;
import org.springframework.transaction.annotation.Propagation;
/**
 * 追问记录表接口实现类
 *
 * @author flyme
 * @date 2021-08-03
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BusOrderQuestionServiceImpl extends BaseServiceImpl<BusOrderQuestionMapper, BusOrderQuestion> implements BusOrderQuestionService {

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, BusOrderQuestion boq, EntityMap extra) {
        return ResultBody.ok();
    }



    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<BusOrderQuestion> cq, BusOrderQuestion boq, EntityMap requestMap) {
      cq.orderByDesc("orderQuestion.createTime");
      return ResultBody.ok();
    }

    @Override
    public ResultBody beforeListEntityMap(CriteriaQuery<BusOrderQuestion> cq, BusOrderQuestion busOrderQuestion, EntityMap requestMap) {
        cq.orderByDesc("orderQuestion.createTime");
        return ResultBody.ok();
    }

    @Override
    public Long countByContent(Long orderId, String askContent) {
        CriteriaQuery cq=new CriteriaQuery(BusOrderQuestion.class);
        cq.eq(true,"orderId",orderId);
        cq.eq(true,"askContent",askContent);
        return count(cq);
    }

    @Override
    public Long countByReplyIsNull(Long orderId) {
        CriteriaQuery cq=new CriteriaQuery(BusOrderQuestion.class);
        cq.eq(true,"orderId",orderId);
        cq.isNull("replyTime");
        return count(cq);
    }
}
